<extend name="Base/common" />
<block name="body">
  <div class="span9 page_message">
    <section id="contents"> 
      <include file="Addons/_nav" /> 
      
      <!-- 数据列表 -->
      <div class="data-table">
        <div class="table">
		<form action="{:addons_url('Jinuser://Jinuser/categorysave')}" name="cateform" id="cateform" method="post">
			<input name="siteid" type="hidden" value="{$siteid}" />
			<input name="columnid" type="hidden" value="{$columnid}" />
			
          <table cellspacing="1">
            <!-- 表头 -->
            <thead>
              <tr>
                <th width="50" >ID</th>
                <th width="50">排序</th>
                <th width="25">&nbsp;</th>
                <th>分类名称</th>
               <!-- <th>下一步提示</th> -->
                <th>&nbsp;</th>
              </tr>
            </thead>
            
            <!-- 列表 -->
            <tbody>
              <volist name="list" id="rs">
                <tr class="list-{$rs['repath']}">
                  <td class="hidden-phone">{$rs['id']}<input name="id[]" type="hidden" value="{$rs['id']}"></td>
				  <td><input type="text" name="nosort{$rs['id']}" datatype="n" value="{$rs['nosort']}" style="width:40px;"></td>
				  <td>{$rs['tree']}</td>
					<td>{$rs['img']}<input type="text" name="name{$rs['id']}" value="{$rs['name']}">
                                               	<a href="{:addons_url('Jinuser://Jinuser/categoryadd').'&pid='.$rs['id'].'&level='.($rs['level']+1).'&parentpath='.$rs['parentpath'].','.$rs['id'].''}" 
						   onClick="return addclass($(this),'{$rs['repath']}',{$rs['id']},{$rs['id']});"  
						   class="text-info"><span class="fa fa-plus"></span> 添加分类</a></td>
                                        <!-- <td>{$rs['details']}</td> -->
					  <td>
					  <span class="pull-right">
					   <a href="{:addons_url('Jinuser://Jinuser/categorymod').'&siteid='.$siteid.'&columnid='.$columnid.'&id='.$rs['id']}"><i class="fa fa-pencil"></i>下一步提示</a>&nbsp;&nbsp;&nbsp;
					
					  <a href="{:addons_url('Jinuser://Jinuser/categorydel'). '&siteid='.$siteid.'&columnid='.$columnid.'&id='.$rs['id']}"
							 data-trigger="confirm" 
							 data-content="确定要删除该分类？删除分类前请先删除该分类下的子分类"><i class="fa fa-times"></i> 删除</a>
					  </span>   
				 </td>
				</tr>
              </volist>
                <tr>
                  <td class="hidden-phone">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><img src="Public/img/cate3.gif" > <a href="{:addons_url('Jinuser://Jinuser/categoryadd').'&pid=0&level=1&parentpath=0'}" 
                  		 onClick="return addclass($(this),'0',1);" class="text-info"><span class="fa fa-plus"></span> 添加分类</a></td>
                  <td>&nbsp;</td>
                </tr>
            </tbody>
          </table>
		  <br/><br/>
                        <div class="span12">

                                <button type="button" class="btn" id ="save">保存分类</button>
                               <!-- <button type="button" class="btn" id="sortform">保存排序</button> -->
				
		  </div>
		  </form>
        </div>
      </div>
      <div class="page"> {$_page|default=''} </div>
    </section>
  </div>
</block>
<block name="script"> 
  <script type="text/javascript">
$(function(){
	$('body').on('hidden', '.modal', function () {$(this).removeData('modal');});
	$(".toggle-subnav").click(function(e) {
        var t = $(this);
        t.parent().toggleClass("subnav-hidden").find(".subnav-menu").slideToggle("fast");
        t.find("span").toggleClass("fa fa-angle-down pull-right").toggleClass("fa fa-angle-right pull-right");
		return false;
    });
	$("li[rel='website-top{$siteid}']").attr('class','active');
	$("li[rel='father{$fatherid}']").attr('class','active');
	$("li[rel='child{$childid}']").attr('class','active');
	$("#cateform").Validform();
	$("#sortform").click(function(){
		$("#cateform").attr("action","{:addons_url('Jinuser://Jinuser/categorysort')}");
		$("#cateform").submit();
	});
	$("#save").click(function(){
		$("#cateform").attr("action","{:addons_url('Jinuser://Jinuser/categorysave')}");
		$("#cateform").submit();
	});
	
})
function addclass(my,parentpath,tp,iconid){
	var h = $("tr[class^='list-"+parentpath+"']");
	var at = h.length>0?h.eq(h.length-1):$('.table tbody');
	if(tp>1 && h.length==0){ at = my.parent('td').parent('tr').eq(0);}
	var url = my.attr('href');
	var lp = $('.newlist')?$('.newlist').length:0;
    $.ajax({
    url : url, 
    type: "POST",
    data: 'lp='+lp, 
    success: function(data){
		$("tr[class^='list-"+parentpath+"-']").show();
		$("span[id='tree-"+iconid+"']").attr('class','fa fa-minus');
		addtrhtml(at,data,1);
    }
    });
	return false;
}
//隐藏显示分类
function showhidetr(strpath, id){
	var faobj = $("span[id='tree-"+id+"']");
	if(faobj.attr('class')=='fa fa-minus'){ //隐藏
		$("tr[class^='list-"+strpath+"-']:visible").hide();
		faobj.attr('class','fa fa-plus');
	}else{ //显示
		$("tr[class^='list-"+strpath+"-']").show();
		faobj.attr('class','fa fa-minus');
	}
}
//加载内容
function addtrhtml(h,t,i){
	if($(".table tbody tr").length==1){
		h.prepend(t);
	}else{
		h.after(t);
	}
	var l = i!=1?i:1;
	h.next('tr').find("input[type='text']").eq(l).focus();
}
function delettr(my){
	my.parent('td').parent('tr').remove();
}
</script> 
</block>
